<!--
 * @Author: wangshuguang
 * @Date: 2022-02-17 10:49:37
 * @LastEditTime: 2022-04-19 20:32:15
 * @LastEditors: wangshuguang
 * @Description:  退款记录
-->
<template>
  <div class="common-container">
    <!-- 筛选条件 -->
    <el-card>
      <el-form
        ref="filterForm"
        :model="listQuery"
        class="demo-form-inline"
        label-width="100px"
      >
        <el-row>
          <el-col :span="24" prop="date">
            <el-form-item label="时间">
              <el-radio-group
                v-model="filterDate"
                size="small"
                @change="dataRadioChange"
              >
                <el-radio-button :label="1">今天</el-radio-button>
                <el-radio-button :label="2">昨天</el-radio-button>
                <el-radio-button :label="7">近7天</el-radio-button>
                <el-radio-button :label="15">近15天</el-radio-button>
                <el-radio-button :label="30">近30天</el-radio-button>
                <el-radio-button label="nowMonth"
                  >本月</el-radio-button
                > </el-radio-group
              >&nbsp;
              <el-date-picker
                v-model="filterTime"
                :clearable="false"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                :default-time="['00:00:00', '23:59:59']"
                size="small"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                @change="pickerChange"
              />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="交易单号" prop="orderNo">
              <el-input
                v-model="listQuery.orderNo"
                placeholder="请输入交易单号"
                size="small"
              />
            </el-form-item>
          </el-col>
          <div v-show="showMoreFilter">
            <el-col :span="11" offset="1">
              <el-form-item label="设备SN" prop="deviceSn">
                <el-input
                  v-model="listQuery.deviceSn"
                  placeholder="请输入设备SN"
                  size="small"
                />
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="会员名称" prop="memberName">
                <el-input
                  v-model="listQuery.memberName"
                  placeholder="请输入会员名称"
                  size="small"
                />
              </el-form-item>
            </el-col>
            <el-col :span="11" offset="1">
              <el-form-item label="会员手机号" prop="memberPhone">
                <el-input
                  v-model="listQuery.memberPhone"
                  placeholder="请输入会员手机号"
                  size="small"
                  maxlength="11"
                />
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="积分兑换状态" prop="status">
                <el-select
                  v-model="listQuery.status"
                  clearable
                  placeholder="请选择"
                  size="small"
                  class="width100"
                >
                  <el-option label="全部" value="" />
                  <el-option
                    v-for="(item, index) in statusOptions"
                    :key="index"
                    :label="item"
                    :value="index"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="11" offset="1">
              <el-form-item label="交易金额区间" prop="highPrice">
                <el-input
                  v-model="listQuery.lowPrice"
                  placeholder="最低价"
                  type="number"
                  :controls="false"
                  size="small"
                  style="width: 100px"
                />
                <span style="margin: 0 1em">-</span>
                <el-input
                  v-model="listQuery.highPrice"
                  placeholder="最高价"
                  type="number"
                  :controls="false"
                  style="width: 100px"
                  size="small"
                />
              </el-form-item>
            </el-col>
          </div>
          <el-col :span="11">
            <el-form-item>
              <el-button type="primary" round size="small" @click="fetchData"
                >查询</el-button
              >
              <el-button
                type="primary"
                round
                size="small"
                @click="resetForm('filterForm')"
                >重置</el-button
              >
              <el-button
                type="text"
                round
                size="small"
                @click="showMoreFilter = !showMoreFilter"
                >{{
                  showMoreFilter ? "收起高级选项" : "展开高级选项"
                }}</el-button
              >
              <el-button type="text" round size="small" @click="downFile"
                >导出为excel</el-button
              >
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <!-- 数据看板 -->
    <!-- <div class="dataCard">
      <el-card>
        <div class="title">退款成功金额/元</div>
        <div class="money">{{ dataCard.refundAmt || 0 }}</div>
        <div class="content">
          <div>共{{ dataCard.refundNum }}笔交易</div>
        </div>
      </el-card>
    </div> -->
    <div class="dataList">
      <el-table size="medium" :data="list" border>
        <el-table-column
          prop="roleTypeZh"
          align="center"
          label="序号"
          width="60px"
        >
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column prop="ordNo" align="center" label="交易单号" />
        <el-table-column prop="snNo" align="center" label="设备SN" />
        <el-table-column prop="memberName" align="center" label="会员名称"
          ><template slot-scope="scope">
            {{ scope.row.memberName || "-" }}
          </template>
        </el-table-column>
        <el-table-column prop="memberPhone" align="center" label="会员手机号" />
        <el-table-column prop="txnAmt" align="center" label="交易金额/元" />
        <el-table-column
          prop="pluginCodeZh"
          align="center"
          label="积分兑换状态"
        >
          <template slot-scope="scope">
            {{ statusOptions[scope.row.status] }}
          </template>
        </el-table-column>
        <el-table-column prop="points" align="center" label="兑换积分/个" />
        <el-table-column prop="txnTm" align="center" label="交易时间" />
        <el-table-column prop="remark" align="center" label="备注" />
      </el-table>
      <div class="pagination-container">
        <el-pagination
          :current-page.sync="listQuery.page"
          :page-size="listQuery.pageSize"
          :total="total"
          layout="total, prev, pager, next"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <!-- 详情弹框 -->
    <!-- <el-dialog
      title="退款订单详情"
      :visible.sync="orderDetailVisible"
      width="70%"
      ><RefundHisDetail v-if="orderDetailVisible" :info-config="infoConfig"
    /></el-dialog> -->
  </div>
</template>

<script>
import { thirdList, export_third_push_order } from "@/api/payCenter";
import { mapGetters } from "vuex";
// import RefundHisDetail from "./components/RefundHisDetail.vue";
import { dateFtt, removePropertyOfNull } from "@/utils";
import { getFilterFormPastTime } from "@/utils/format";

export default {
  //   components: { RefundHisDetail },
  data() {
    return {
      orderDetailVisible: false,
      showMoreFilter: false,
      infoVisible: false,
      infoConfig: {},
      form: {},
      dataCard: {},
      scope: 0,
      total: 0,
      filterDate: 1,
      filterTime: [],
      listQuery: {
        page: 1,
        pageSize: 10,
        deviceSn: "",
        highPrice: "",
        lowPrice: "",
        memberName: "",
        memberPhone: "",
        orderNo: "",
        status: "",
      },
      statusOptions: {
        0: "兑换失败",
        1: "兑换成功",
      },
      list: [],
    };
  },

  computed: {
    ...mapGetters(["businessInfo", "userInfo"]),
  },
  async mounted() {
    // 设置时间查询默认值
    this.filterDate = 1;
    this.dataRadioChange(1);
  },
  methods: {
    viewData(data) {
      this.infoConfig = data;
      this.orderDetailVisible = true;
    },
    pickerChange(val) {
      // 时间筛选条件切换
      this.listQuery.beginTime = val[0];
      this.listQuery.endTime = val[1];
      this.filterDate = "";
      this.fetchData();
    },
    async dataRadioChange(val) {
      // 时间tab切换
      let dateArr = [];
      if (val == "nowMonth") {
        dateArr = await getFilterFormPastTime("nowMonth");
      } else if (val == 2) {
        dateArr = await getFilterFormPastTime("yesterday");
      } else {
        dateArr = await getFilterFormPastTime(val);
      }
      this.listQuery.beginTime = dateArr[0];
      this.listQuery.endTime = dateArr[1];
      this.filterTime = [];
      this.fetchData();
    },
    // 重置
    resetForm(formName) {
      this.filterDate = 1;
      this.listQuery.endAmt = "";
      this.listQuery.beginAmt = "";
      this.$refs[formName].resetFields();
      this.dataRadioChange(1);
    },
    downFile() {
      //   let { isAdmin, shopId } = this.userInfo;
      const obj = {
        ...this.listQuery,
      };
      export_third_push_order(removePropertyOfNull(obj)).then((res) => {
        if (res.code === 0) {
          this.$alert("数据导出中，请稍后到数据下载中心进行下载", "提示", {
            confirmButtonText: "确定",
            center: true,
            type: "success",
            callback: (action) => {},
          });
        }
      });
    },
    fetchData() {
      const obj = {
        ...this.listQuery,
      };
      console.log(removePropertyOfNull(obj));
      thirdList(removePropertyOfNull(obj)).then((res) => {
        if (res.code === 0) {
          const { list, total } = res.data;
          console.log("res", res);
          this.list = list;
          this.total = total;
        }
      });
    },
    handleSizeChange(val) {
      this.listQuery.pageSize = val;
      this.fetchData();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.fetchData();
    },
  },
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.labelText {
  color: rgb(115, 115, 115);
  font-size: 12px;
}
.common-container {
  // background: #fff;
  border-radius: 5px;
  padding: 20px;
  .dataCard {
    display: flex;
    /deep/.el-card {
      margin: 10px 10px 10px 0;
      min-width: 200px;
      .el-card__body {
        padding: 10px 20px;
        .title {
          border-left: 3px solid #ffb72f;
          padding-left: 5px;
        }
        .money {
          font-size: 20px;
          margin-top: 15px;
        }
        .content {
          margin-top: 15px;
          font-size: 12px;
        }
      }
    }
  }
  .dataList {
    background: #fff;
    padding: 10px 30px;
  }
}
</style>
